<?php
global $USER_LEVEL;

function printTH($name, $sort, $sort_arr)
{
	$link = 'user/?sort='.$sort.'-'.($sort_arr[0] == $sort && $sort_arr[1] == 'asc' ? 'desc' : 'asc');
	$gradus = $sort_arr[0] == $sort && $sort_arr[1] == 'asc' || $sort_arr[0] != $sort ? '090' : '270';
	$small = $sort_arr[0] != $sort ? '_small' : '';
	$title = $gradus == '090' ? 'По возрастанию' : 'По убыванию';
	?>
	<th><?=$name?> <a href='<?=$link?>' class='icon_sort'><img src='<?=config_item('image_path')?>images/icons/control_double_<?=$gradus.$small?>.png' width='16' height='16' title='<?=$title?>'></a></th>
	<?
}

?>
<h1>Участники (<?=$count_all_users?>) <span style="font-size:13px;">
<?php foreach($count_my_users as $k => $v){ ?>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<?=$USER_LEVEL[$k]?>и: <?=$v?>
<?php } ?>
</span></h1>

<script language="javascript" src='<?=config_item('js_path')?>js/user_index.js?<?=time()?>'></script>
<script language="javascript" src='<?=config_item('js_path')?>js/table_list.js?<?=time()?>'></script>

<a href='#' onclick="document.getElementById('filter').style.display = document.getElementById('filter').style.display == 'none' ? '' : 'none'; return false;">Поиск</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<?php if($me['level'] > '*' && @$_GET['open'] != 'all') { ?>
	<a href='user/?open=all'>Открыть все</a>
<?php } ?>

<form method=post action='user/?open=all' enctype='multipart/form-data' id="filter" style="margin-top:10px; display:none;">
	E-mail: <input type='text' name='email' value=''>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	ФИО: <input type='text' name='fio' value=''>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type='submit' value='Найти'>
</form>

<table class='list' cellspacing=0 id='users' style="margin-top:20px;">
	<thead>
		<tr>
			<th></th>
			<?php printTH('Статус', 'status', $sort_arr);  ?>
			<?php printTH('ФИО', 'fio', $sort_arr);  ?>
			<?php printTH('Дата регистрации', 'date', $sort_arr);  ?>
			<?php printTH('Откуда', 'where', $sort_arr);  ?>
			<?php printTH('Контакты', 'email', $sort_arr);  ?>
			<?php printTH('Реферер', 'referer', $sort_arr);  ?>
			<th></th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<th colspan=8 style="text-align:left">Руководитель: <?=@$USER_LEVEL[$my_parent['level']].' '.@$my_parent['fio']?></th>
		</tr>

	</tbody>
</table>


<br><br><br><br>
<h1>Рефереры сторонние</h1>

<table class='list' cellspacing=0>
	<thead>
		<tr>
			<th></th>
			<th>Статус</th>
			<th>ФИО</th>
			<th>E-mail</th>
			<th>Контакты</th>
		</tr>
	</thead>
	<tbody>
	<?php $i = 0; foreach($referers as $ref) {
		$i++;
		?>
		<tr>
			<td><?=$i?></td>
			<td><?=@$ref['status']?></td>
			<td><?=@$ref['fio']?></td>
			<td><?=@$ref['email']?></td>
			<td><?
			echo @$ref['skype'] ? "Skype: ".$ref['skype']."<br>" : '';
			echo @$ref['icq'] ? "ICQ: ".$ref['icq']."<br>" : '';
			echo @$ref['phone'] ? "Телефон: ".$ref['phone']."<br>" : '';
			?></td>
		</tr>
	<?php } ?>
	</tbody>
</table>



<script language="javascript">

$(document).ready(function(){

	UserTable.init({
		'tId': 'users'
	});
<?php foreach($me_json as $parent_id => $arr) { ?>
	UserTable.addRowsByJson(<?=json_encode($arr)?>, <?=$parent_id?>);
<?php } ?>

<?php if(count($find_id)) { ?>
	UserTable.selectRows(<?=json_encode($find_id)?>);
	UserTable.goToFirstSelected();
<?php } ?>

});

</script>

